package bishihuizong;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by JiaJia on 2019/9/16 0016.
 */
public class Yuanfudao01 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int row=scanner.nextInt();
        int col=scanner.nextInt();
        int[][] num=new int[row][col];
        for (int i = 0; i <row ; i++) {
            for (int j = 0; j <col ; j++) {
                num[i][j]=scanner.nextInt();
            }
        }
        ArrayList<Integer> list=new ArrayList<>();
        int left=0,top=0,right=col-1,bottom=row-1;
        while (left<=right&&top<=bottom){
            for (int i = top; i <=bottom ; i++) {
                list.add(num[i][left]);
            }
            for (int i = left+1; i <=right ; i++) {
                list.add(num[bottom][i]);
            }
            if (top!=bottom){
                for (int i = bottom-1; i >=top ; i--) {
                    list.add(num[i][right]);
                }
            }
            if (left!=right){
                for (int i =right-1; i >left ; i--) {
                    list.add(num[top][i]);
                }
            }
            top++;left++;right--;bottom--;
        }
        for (int i:list){
            System.out.print(i+" ");
        }
    }
}